package com.yicoollxing.controller.backend;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yicoollxing.common.Const;
import com.yicoollxing.common.ServerResponse;
import com.yicoollxing.pojo.User;
import com.yicoollxing.service.IUserService;
import com.yicoollxing.service.impl.UserServiceImpl;


@Controller
@RequestMapping("/manager/user")
public class UserManagerController {
	
	@Autowired
	private IUserService iUserService;


	
	
	@RequestMapping("/login.do")
	@ResponseBody
	public ServerResponse  doLoing(@RequestParam(required=true)String username,@RequestParam(required=true)String password,HttpSession session){
		
		ServerResponse  response=iUserService.doLogin(username, password);
		if(response.isSuccess()){
			User user=(User) response.getData();
			if(user!=null){
				if(user.getRole()==Const.Role.ROLE_ADMIN){
					session.setAttribute(Const.CURRENT_USER, user);
				}else{
					return ServerResponse.createByErrorMessage("当前用户不是管理员用户");
				}
			}
		}
		
		return response;
	}

}
